<?php
/* 补丁生成程序 */

$f='/application/modules/yw/model/Plugin.model.php';

$f = explode('
', $f);

foreach($f as $a) {
    echo 'copy:'.$a."\n";
    //continue;
    $a = str_replace("\\", '/', $a);
    $m = dirname(__FILE__) . '/../patch_722' .$a;
    $n = dirname(__FILE__) . '/../' . $a;

    mkdirs($m, 1);

    if(is_dir($n)) {
        //dircpy($n,$m);
    } else {
        copy($n,$m);
    }
}

function mkdirs($dir, $isFile = 0)
{
    $arr  = explode('/',$dir);
    $path = implode('/',$arr);
    $adir = explode('/',$path);
    $dirlist = '';
    $rootdir = array_shift($adir);
    if($isFile) {
        array_pop($adir);
    }

    if(($rootdir!='.'||$rootdir!='..')&&!file_exists($rootdir))
    {
        @mkdir($rootdir);
    }
    foreach($adir as $key=>$val)
    {
        if($val!='.'&&$val!='..')
        {
            $dirlist .= "/".$val;
            $dirpath = $rootdir.$dirlist;
            if(!file_exists($dirpath))
            {
                @mkdir($dirpath);
                @chmod($dirpath,0777);
            }
        }
    }
}


function dircpy($source, $dest, $overwrite = false){

  if($handle = opendir( $source)){        // if the folder exploration is sucsessful, continue
   while(false !== ($file = readdir($handle))){ // as long as storing the next file to $file is successful, continue
     if($file != '.' && $file != '..'){
       $path = $source . '/' . $file;
       if(is_file( $path)){
         if(!is_file( $dest . '/' . $file) || $overwrite)
           if(!@copy( $path,  $dest . '/' . $file)){
             echo '<font color="red">File ('.$path.') could not be copied, likely a permissions problem.</font>';
           }
       } elseif(is_dir( $path)){
         if(!is_dir( $dest . '/' . $file))
           mkdir( $dest . '/' . $file); // make subdirectory before subdirectory is copied
         dircpy($path, $dest . '/' . $file, $overwrite); //recurse!
       }
     }
   }
   closedir($handle);
  }
}